package com.dyz.leetcode._01_array;

public class _80_removeDuplicates {
    //双指针
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if(n<=2){return n;}
        int start = 1;
        int end = 2;
        while(end<n){
            if(nums[end]!=nums[start-1]){
                start++;
                nums[start] = nums[end];
            }
            end++;
        }
        return start+1;
    }
    public int removeDuplicates1(int[] nums) {
        if (nums.length <= 2) return nums.length;
        int slow = 2; // 已经处理区域的最后一个位置的下一个位置
        int fast = 2;
        while (fast < nums.length) {
            if (nums[fast] != nums[slow - 2]) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
}
